package org.example.design.facade.test2;

/**
 * @author huangshen
 * @version 0
 * @description Head
 * @since 2022/2/10 16:56
 */
public class Head {
    /**
     * 耳朵引用变量
     */
    private final Ear ear;

    /**
     * 大脑引用变量
     */
    private final Brain brain;

    /**
     * 头引用变量
     */
    private static Head head = null;

    private Head(){
        ear = new Ear();
        brain = new Brain();
    }

    /**
     * 获得Head头单例
     * @return
     */
    public static Head getInstance(){
        synchronized(Head.class){
            if(head == null){
                return new Head();
            }
            return head;
        }
    }

    /**
     * "听"后明白了话语
     */
    public void explainWords(String words){

        //别人对我说了句话，我耳朵“听”到了
        String yourWords = ear.getWords(words);

        //但是我的耳朵并不理解别人说的什么意思，于是交给我的大脑
        ear.sendWordsToBrain(brain, yourWords);

        //我的大脑分析话语
        brain.explainWords();
    }

}